
package uk.ac.cam.cl.oscar.sift;
import java.io.*;

/**
 * A class to represent a descriptor of a Keypoint.  A Descriptor
 * is a series of numbers that represent the gradient of the image
 * around a keypoint.
 */
public class KeypointDescriptor implements Serializable
{
    private double desc[]; // Descriptors
    private int yDim, oDim;

    /**
     * Creates a new keypoint descriptor with given x-dimension
     * y-dimension and o-dimension, and instantiates the descriptors
     * with 0.0.
     *
     * @param xDim x-dimension
     * @param yDim y-dimension
     * @param oDim o-dimension
     */
    public KeypointDescriptor(int xDim, int yDim, int oDim)
    {
        this.yDim = yDim;
        this.oDim = oDim;
        desc = new double[xDim * yDim * oDim];
        for (int n=0; n<desc.length; n++) {
           desc[n] = 0.0;
        }
    }

    /** Gets the given value in a linear fashion from the descriptor
     * array
     */
    public double linearGet(int idx) { return desc[idx]; }
    /** Sets the given value in the descriptor array.  */
    public void linearSet(int idx, double value) { desc[idx] = value; }
    /** Returns the length of the descriptor array for use by linearGet/Set */
    public int getLinearDim() { return desc.length; }
    /** Get the given value in terms of the x,y coordinates */
    public double get(int xI, int yI, int oI) { return desc[xI * yDim * oDim + yI * oDim + oI]; }
    /** Set the given value in terms of the x,y coordinates */
    public void set(int xI, int yI, int oI, double value) { desc[(xI * yDim * oDim) + (yI * oDim) + oI] = value; }

}
